/*
package org.example.springboot.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.example.springboot.component.SseEmitterServer;
import org.example.springboot.entity.*;
import org.example.springboot.service.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalTime;
import java.util.List;

@Slf4j
@Component
public class cumulativeETHandler {

    @Value("${xxl.job.admin.addresses}")
    private String adminAddresses;

    @Resource
    private ColDeviceDataComputesynchService colDeviceDataComputesynchService;

    @Resource
    private IrrigationUnitService irrigationUnitService;

    @Resource
    private ETService etService;

    @Resource
    private FmcDataService fmcDataService;

    @Resource
    private FmcMetricsService fmcMetricsService;

    @Resource
    private SseEmitterServer sseEmitterServer;

    @XxlJob("cumulativeETHandler")
    public void cumulativeETHandler() {
        // 获取任务参数
        String jobParam = XxlJobHelper.getJobParam();

        // 获取任务ID
        long jobId = XxlJobHelper.getJobId();
        // 记录任务执行日志
        log.info("cumulativeETHandler-ET累计任务已执行，任务ID：{}，参数：{}", jobId, jobParam);
        List<FmcMetrics> fmcMetricsList = fmcMetricsService.list();
        for (FmcMetrics fmcMetrics : fmcMetricsList) {
            IrrigationUnit irrigationUnit = irrigationUnitService.getOne(new QueryWrapper<IrrigationUnit>().eq("control_device", fmcMetrics.getDid()));
            if (null != irrigationUnit) {
                ET et = etService.getOne(new QueryWrapper<ET>().eq("irrigation_unit_uuid", irrigationUnit.getUuid()));
                if (null == et) {
                    throw new RuntimeException("ET信息不存在");
                }
                String equipmentId = et.getEquipmentId();
                // 如果设备信息不为空
                // 获取当前时间
                LocalTime now = LocalTime.now();
                LocalTime time = LocalTime.of(19, 0);
                LocalTime time1 = LocalTime.of(7, 0);
                if(StringUtils.isNotBlank(equipmentId) && !now.isAfter(time) && !now.isBefore(time1)){
                    // 根据设备ID和格式化后的时间查询最新的数据计算记录
                    FmcData fmcData = fmcDataService.getOne(new QueryWrapper<FmcData>()
                            .eq("did", equipmentId)
                            .orderByDesc("ctime").last("limit 1"));
                    if(null != fmcData){
                        log.info("FmcData表ID：{}",fmcData.getId());
                        ColDeviceDataComputesynch deviceDataComputesynch = colDeviceDataComputesynchService.getOne(new QueryWrapper<ColDeviceDataComputesynch>().eq("data_id", fmcData.getId()));
                        // 如果查询到了数据计算记录
                        if (null != deviceDataComputesynch) {
                            // 更新蒸散量指标记录
                            log.info("deviceDataComputesynch表ET值：{}",deviceDataComputesynch.getEtt0());
                            float et1 = deviceDataComputesynch.getEtt0() +(fmcMetrics.getEt() == null ? 0 : fmcMetrics.getEt());
                            log.info("当前ET值：{}",et1);
                            fmcMetricsService.update(new UpdateWrapper<FmcMetrics>().set("et", et1).eq("id", fmcMetrics.getId()));
                            // 推送更新通知
                            sseEmitterServer.broadcast("Refresh");
                        }
                    }
                }
            }

        }
    }

}
*/
